package com.itheima.hmshopping.exceptionhander;


import com.itheima.hmshopping.util.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//全局异常处理
@RestControllerAdvice
public class ExceptionHander {
    //义务异常
    @ExceptionHandler(CustomException.class)
    public R customException(CustomException exception){
        return R.error(exception.getMessage());
    }

    //处理不可预知的异常
    @ExceptionHandler(Exception.class)
    public R handlerException1(Exception be) {
        be.printStackTrace();
        return R.error("系统异常");
    }
}
